﻿using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using VietTrips.Domain.Models;

namespace VietTrips.Domain.Contexts
{
    public class UsersContext : DbContext
    {
        public UsersContext()
            : base("DefaultConnection")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Role>().HasMany<UserProfile>(s => s.UserProfiles).WithMany(c => c.Roles).Map(c =>
            {
                c.MapLeftKey("RoleId");
                c.MapRightKey("UserId");
                c.ToTable("webpages_UsersInRoles");
            });
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<UserProfile> UserProfiles { get; set; }
        public DbSet<Role> Roles { get; set; }
    }
}